<script>
    $('#upload_organization_frame #file-address').bind('click', function(event) {
        $('#upload_organization_frame [type="file"]').click();
    });
    $('#upload_organization_frame [type="file"]').bind('change', function(event) {
        if (this.files.length == 0) {
            $('#upload_organization_frame #file-address').html('请选择文件');
        } else {
            $('#upload_organization_frame #file-address').html(this.value);
        }
    });
    $('#upload_organization_frame #upload-file-button').bind('click', function() {
        if ($('#upload_organization_frame [type="file"]')[0].files.length == 0) {
            alert('请先选择要上传的文件');
            return;
        } else {
            $(this).hide();
            $('#upload_organization_frame #upload-pro').addClass('change-upload-pro');
            setTimeout(function() {
                $('#upload_organization_frame .upload-pro-ed-notify').show(250);
            },1200);
            setTimeout(function() {
                var data = new FormData($('#upload_organization_frame form')[0]);
                var xhr = new XMLHttpRequest();
                xhr.upload.onprogress = function(e){
                    var pro = e.loaded / e.total;
                    $('#upload_organization_frame .upload-pro-ed-notify').html(pro*100+'%');
                    $('#upload_organization_frame #upload-pro-ed').css({'width':pro*100+'%'});
                    if (pro == 1) {
                        $('#upload_organization_frame .upload-pro-ed-notify').html('导入中..');
                    }
                }
                xhr.onload = function(e){
                    var res = JSON.parse(e.srcElement.responseText);
                    if (res.isOk == 0) {
                        notification({'title':'错误', 'message':res.msg},'error');
                    } else {
                        setTimeout(function() {
                            $('#upload_organization_frame .upload-pro-ed-notify').html('完成');
                        },500);
                        var totalCount = res['total'];
                        var falseCount = res['false'];
                        $('#upload_organization_frame .res-success span').html(totalCount - falseCount);
                        $('#upload_organization_frame .res-false span').html(falseCount);
                        var list = res['falseList'];
                        $('#upload_organization_frame .upload-log-table table tbody').html('');
                        for (var i = 0; i < list.length; i++) {
                            var tr =$('<tr></tr>');
                            tr.html('<td>'+list[i]['target']+'</td><td>'+list[i]['msg']+'</td>');
                            $('#upload_organization_frame .upload-log-table table tbody').append(tr);
                        }
                    }

                }
                xhr.open('post', baseApiPath + 'owner_info/upload/organization', true);
                xhr.send(data);
            }, 1250);
        }
    });
</script>